<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>文章添加--layui后台管理模板</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="../../js/layui/css/layui.css"
	media="all" />
<script src="../../js/layui/layui.js"></script>
<link rel="stylesheet" href="../../css/font_eolqem241z66flxr.css"
	media="all" />
<link rel="stylesheet" href="../../css/news.css" media="all" />
<style type="text/css">
.layui-table-cell {
	text-align: center;
	height: auto;
	white-space: normal;
	width: auto;
}
</style>
</head>
<body class="childrenBody">
		<script type="text/html" id="barDemo">
			<a class="layui-btn layui-btn-sm" lay-event="edit" ><i class="layui-icon layui-icon-edit"></i>编辑</a>
			<a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
		</script>
		<div class="layui-inline">
			<a class="layui-btn layui-btn-normal newsAdd_btn">添加产品</a>
		</div>
	<table class="layui-table" id="news" lay-filter="table">
	</table>
		

	<script type="text/javascript">
	layui.use([ 'upload', 'layer' ,'table'], function() {
		var upload = layui.upload, $ = layui.$,table=layui.table, layer = layui.layer;
		
		 var data=JSON.parse(sessionStorage.getItem("product"));
			
			table.render({
				elem : '#news',
				url : 'http://localhost:8080/Greenleaf/pdtImg/getPdtImgs',//数据接口
				where : {
					alternative1 : data.pdtId
				},
				page : true, 
				 groups: 1,
				 limit:5,
				 limits:[5,6,7], 
				cols : [ [ //表头
				{field : 'imgId',title : '编号',sort : true}
				,{field : 'imgUrl',title : '图片',templet : '<div><img src="../../../{{d.imgUrl}}" /></div>'}
				,{field : 'weight',title : '权重'}
				,{title : '操作',align : 'center',fixed : 'right',toolbar : '#barDemo'}
				] ],
				id : "ProductReload"
			});
			table.on('tool(table)',function(obj) {
				var data = obj.data; 
				var layEvent = obj.event; 
				var tr = obj.tr; 
				sessionStorage.setItem("product",JSON.stringify(data));
				if (layEvent === 'del') { //删除
					layer.confirm('真的删除行么',function(index) {
							layer.close(index);
								$.post("http://localhost:8080/Greenleaf/pdtImg/del",
										{pdtImg : data.imgId},
												function(res) {
													if (res.success) {obj.del();
														layer.msg('删除成功',{
																			icon : 1,
																			time : 1500
																		});
														location.reload();
													} else {
														layer.msg(res.message,{
																			icon : 2,
																			time : 1500
																		});
															}
													location.reload();
														},"json")
									});
				} else if (layEvent === 'edit') { //编辑
					var id = data.dId;
					var index = layui.layer
							.open({
								title : "编辑图片",
								type : 2,
								area: ['400px', '400px'],
								content : "productImgUpdate.html",
								success : function(
										layero,
										index) {
									layui.layer
											.tips(
													'点击此处返回产品列表',
													' .layui-layer-close',
													{
														tips : 3
													});
								},
								end : function() {
									location.reload();
								}
							})

				}
			});
			$(".newsAdd_btn").click(
					function() {
						var index = layui.layer.open({
							title : "添加产品图片",
							type : 2,
							content : "productImgAdd.html",
							
							end : function() {
								location.reload();
							}
						})
						//改变窗口大小时，重置弹窗的高度，防止超出可视区域（如F12调出debug的操作）
						$(window).resize(function() {
							layui.layer.full(index);
						})
						layui.layer.full(index);
					});
			
	});
	
	</script>

</body>
</html>